package com.rg.servlet;

import com.rg.model.OrderModel;
import com.rg.model.UserModel;
import com.rg.service.OrderService;
import org.apache.commons.dbutils.DbUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;

@WebServlet("/OrderConfirmServlet")
public class OrderConfirmServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        OrderModel order = (OrderModel) request.getSession().getAttribute("order");
        order.setDatetime(new Date());
        order.setStatus(2);
        order.setUser((UserModel) request.getSession().getAttribute("user"));
        OrderService orderService=new OrderService();
        orderService.addOrder(order);
        request.getSession().removeAttribute("order");
        request.setAttribute("msg", "订单支付成功！");
        request.getRequestDispatcher("order_success.jsp").forward(request, response);
    }
}
